<?php
/**
 * class App_Form_User_Register
 * common user register form
 *
 */
class App_Form_User_Register extends Zend_Form
{
    /**
     * init the form
     *
     * @return object
     */
    public function init()
    {
        $this->setMethod('post');

        // get countries list
        $country = new App_Model_Country();
        $countries = $country->listAll();

        // get foods list
        $food = new App_Model_Food();
        $foods = $food->listAll();

        // Add an email element
        $this->addElement('text', 'email', array(
            'required'      => true,
            'label'         => 'Email',
            'filters'       => array('StringTrim'),
            'validators'    => array('EmailAddress')
        ));

        // Add an first name element
        $this->addElement('text', 'firstname', array(
            'required'  => true,
            'label'     => 'First Name',
            'filters'   => array('StringTrim')
        ));

        // Add an last name element
        $this->addElement('text', 'lastname', array(
            'required'  => true,
            'label'     => 'Last Name',
            'filters'   => array('StringTrim')
        ));

        // Add gender element
        $this->addElement('radio', 'gender', array(
            'required'  => false,
            'value'     => '3',
            'label'     => 'Gender',
            'separator' => ' ',
            'multiOptions' => array(
                '1' => 'Male',
                '2' => 'Female',
                '3' => 'Prefer not to say'
            )
        ));

        // Add gender element
        $this->addElement('radio', 'location', array(
            'required'  => false,
            'value'     => '1',
            'label'     => 'Pick location by',
            'separator' => ' ',
            'multiOptions' => array(
                '1' => 'Zip',
                '2' => 'City'
            )
        ));

        // Add country element
        $this->addElement('select', 'country_id', array(
            'required'  => false,
            'label'     => 'Countrys',
            'multiOptions' => $countries
        ));

        // Add state element
        $this->addElement('select', 'state_id', array(
            'required'  => false,
            'label'     => 'State',
            // should be set to false when using ajax
            'registerInArrayValidator' => false,
            'multiOptions' => array('0' => ' --- ')
        ));

        // Add city element
        $this->addElement('select', 'city_id', array(
            'required'  => false,
            'label'     => 'City',
            'registerInArrayValidator' => false,
            'multiOptions' => array('0' => ' --- ')
        ));

        // Add zip element
        $this->addElement('text', 'zip', array(
            'required'  => false,
            'label'     => 'Your Zip/Postal Code',
            'filters'   => array('StringTrim')
        ));

        // Add mailinglist element
        $this->addElement('radio', 'is_mailinglist', array(
            'required'  => false,
            'value'     => '0',
            'label'     => 'Would you like to receive email reviews of restaurants?',
            'separator' => ' ',
            'multiOptions' => array(
                '1' => 'Yes',
                '0' => 'No'
            )
        ));

        // Add food element
        $this->addElement('multiselect', 'user_food', array(
            'required'  => false,
            'label'     => 'Which types of foods do you like? (Hold down the CTRL key to select more than one)',
            'size'      => 8,
            'multiOptions' => $foods
        ));

        // Add description element
        $this->addElement('textarea', 'bio', array(
            'required'  => false,
            'cols'      => '55',
            'rows'      => '8',
        ));

        // Add the submit button
        $this->addElement('submit', 'submit', array(
            'ignore'    => true,
            'label'     => 'Click to become a Dine.com member',
        ));

        // And finally add some CSRF protection
        //$this->addElement('hash', 'csrf', array('ignore' => true));
    }
}